package com.rd.teacher.jichao.day18;


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class TestOutputStream {

    // 拷贝文件
    public static void main(String[] args) throws Exception {
        copyFile("stream.txt", "streamCopy.txt");
    }

    public static void copyFile(String srcPath, String destPath)
            throws Exception {
        // 根据文件地址 获取输入输出流
        InputStream is = new FileInputStream(srcPath);
        OutputStream os = new FileOutputStream(destPath);
        byte[] arr = new byte[1024];
        int len = 0;
        while ((len = is.read(arr)) != -1) {
            os.write(arr, 0, len);
        }

        os.close();
        is.close();
    }
}
